$(function () {
    //回车事件
    if (event.keyCode == 13) {//回车键的键值为13
        document.getElementByIdx_x("input").click();  //调用登录按钮的登录事件
    }
    //获得焦点效果
    $("#oldPassword").focus();
})

function save() {
    //获取用户登入时的id
    var id = localStorage["name"];
    //获取用户的原密码
    requestAjax("../newpassword/showAdmin.htm", "get", "JSON", "id=" + id, function (data) {
        //数据库原来的密码
        var userPassword = (data.data.password);
        //获取前台输入的值
        // oldPassword 旧密码
        var oldPassword = $("input[name=\"oldPassword\"]").val();
        // newPassword 要修改的密码
        var newPassword = $("input[name=\"newPassword\"]").val();
        // confirmpasswordint 确认密码
        var confirmpasswordint = $("input[name=\"reNewPassword\"]").val();
        // var all = JSON.stringify(data.data);
        // console.log(all);
        // console.log("数据库旧密码是：" + userPassword + "旧密码是：" + oldPassword + "新密码是：" + newPassword + "确认密码是：" + confirmpasswordint)
        if (userPassword == oldPassword) {
            if (newPassword == confirmpasswordint) {
                requestAjax("../newpassword/updatepPassword.htm", "get", "JSON", "oldpassword=" + oldPassword + "&newpassword=" + newPassword + "&confirmpasswordint=" + confirmpasswordint + "&id=" + id, function (data) {
                    if (data.result) {
                        layer.msg(data.msg);
                        alert("请重新登入！")
                        window.history.go(-1);
                    } else {
                        layer.msg(data.msg);
                    }
                })
            } else {
                layer.msg("两次新密码不一样")
            }
        } else {
            layer.msg("密码不正确")
        }
    })
}